package com.gufe.controller.user.mp.Exhibitions;

import com.gufe.dto.Exhibitions.ReservationDTO;
import com.gufe.entity.Exhibitions.Exhibition;
import com.gufe.result.Result;
import com.gufe.service.user.mp.Exhibition.ExhibitionService;
import com.gufe.vo.Exhibitions.ExhibitionVO;
import com.gufe.vo.Exhibitions.ReservationVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/exhibition")
public class ExhibitionController {

    @Autowired
    private ExhibitionService exhibitionService;

    @GetMapping("/list")
    public Result<List<ExhibitionVO>> getExhibitionList() {
        List<ExhibitionVO> exhibitions = exhibitionService.getAllExhibitions();
        return Result.success(exhibitions);
    }

    @PostMapping("/reserve")
    public Result<String> reserveExhibition(@RequestBody @Valid ReservationDTO reservationDTO) {
        try {
            exhibitionService.reserveExhibition(reservationDTO);
            return Result.success("预约成功");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/cancel-reserve")
    public Result<String> cancelReservation(@RequestBody ReservationDTO reservationDTO) {
        try {
            exhibitionService.cancelReservation(reservationDTO);
            return Result.success("取消预约成功");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @GetMapping("/reservation-status")
    public Result<ReservationVO> getReservationStatus(@RequestParam String studentId) {
        ReservationVO reservationVO = exhibitionService.getReservationStatus(studentId);
        return Result.success(reservationVO);
    }

}